import axios, { AxiosResponse } from 'axios';
export default class AjaxResquest {
  private url: string;
  private status: boolean;
  // private params: object;
  constructor(url: string) {
    this.url = url;
    this.status = false;
  }
  public getFunction(data?: object): Promise<any> {
    if (this.status) {
      return new Promise((reslove, reject) => {
        reslove({ data: { code: 10086, message: '不要重复提交' } });
      });
    } else {
      this.status = true;
      return new Promise((reslove, reject) => {
        axios
          .post(this.url, data)
          .then((res: AxiosResponse) => {
            this.status = false;
            reslove(res);
          })
          .catch(reject => {
            this.status = false;
            return reject;
          });
      });
    }
  }
}
